<%@ page import="com.wuming.caiwu.security.SecurityHander" %><%--
  Created by IntelliJ IDEA.
  User: hanfei
  Date: 18/6/27
  Time: 下午3:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${allServerPath}static/css/bootstrap.min.css">
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${allServerPath}static/layui/css/style.css">
    <link rel="stylesheet" href="${allServerPath}static/layui/css/public.css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

    <style>
        .tab_zp td span {
            font-weight: bold;
            color: #003399;
        }

        ::-moz-placeholder {
            color: #d4d4d4;
        }

        ::-webkit-input-placeholder {
            color: #d4d4d4;
        }

        :-ms-input-placeholder {
            color: #d4d4d4;
        }

    </style>
</head>
<body>
<div style="padding: 15px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>用户基本信息</legend>
    </fieldset>

    <form class="layui-form" action="" id="roleForm">
        <div class="layui-row">
            <div class="layui-col-md12">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名</label>

                    <div class="form-group layui-input-block" style="width: 450px;">
                        <input type="text" name="username" placeholder="" autocomplete="off"
                               class="layui-input" style="width: 50%;display: inline-block"
                               value="${user['username']}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">用户昵称</label>

                    <div class="form-group layui-input-block" style="width: 450px;">
                        <input type="text" name="nickName" placeholder="" autocomplete="off"
                               class="layui-input" style="width: 50%;display: inline-block"
                               value="${user['nickName']}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>

                    <div class="form-group layui-input-block" style="width: 450px;">
                        <input type="text" name="email" placeholder="" autocomplete="off"
                               class="layui-input" style="width: 50%;display: inline-block"
                               value="${user['email']}">
                    </div>
                </div>
                <div class="layui-form-item">
                        <label class="layui-form-label">角色</label>
                        <div class="form-group layui-input-inline">
                            <select id="roleId" name="roleId" lay-filter="roleId">
                                <option value=""></option>
                            </select>
                        </div>
                </div>
            </div>
        </div>
        <input type="hidden" name="qsgStoreId" value="${user['qsgStoreId']}"/>
        <input type="hidden" name="id" value="${user['id']}"/>
    </form>
    <%--<div class="layui-row">--%>
        <%--<div class="layui-col-md12">--%>
            <%--<div class="layui-form-item">--%>
                <%--<button class="layui-btn" type="button" name="btnSave" id="btnSave" lay-filter="role">保存用户信息--%>
                <%--</button>--%>
            <%--</div>--%>
        <%--</div>--%>
    <%--</div>--%>

</div>

<script src="${allServerPath}static/layui/layui/layui.js" charset="utf-8"></script>
<script src="${allServerPath}static/js/jquery-2.1.4.min.js" charset="utf-8"></script>
<script src="${allServerPath}static/js/bootstrap.min.js" charset="utf-8"></script>
<script type="text/javascript" src="${allServerPath}static/js/bootstrapValidator.js"></script>
<script type="text/javascript" src="${allServerPath}static/js/common/date-util.js"></script>

<script>
    layui.use(['layer', 'form', 'laydate', 'jquery', 'upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery;


        $(document).ready(function(){
            $.ajax({
                type: 'get',
                url: '${allServerPath}web/sysrole/getAll.htmls',
                dataType: 'JSON',
                success: function (obj) {
                    if (obj.success) {
                        $.each(obj.data, function (index, item) {
                            var s = "<option value='" + item.id + "'>" + item.name + "</option>";
                            $("#roleId").append(s);
                        })
                        var currentRoleId = '${currentRoleId}';
                        if(null != currentRoleId && "null" != currentRoleId){
                            $("#roleId").val(currentRoleId);
                        }
                        form.render();
                    }
                }
            });
        });

        <%--console.log("=============" + userrole);'--%>
        <%--var currentRoleId = '${roleId}';--%>
        <%--$("#roleId").val(currentRoleId);--%>
        <%--form.render();--%>

        <%--var status = '${role.status}';--%>
        <%--if ('' == status) {--%>
            <%--$("#status").find("option[value='1']").attr("selected", true);--%>
        <%--} else {--%>
            <%--$("#status").val(status);--%>
        <%--}--%>

        <%--var isMemberRole = '${role.isMemberRole}';--%>
        <%--if ('' == isMemberRole) {--%>
            <%--$("#isMemberRole").find("option[value='0']").attr("selected", true);--%>
        <%--} else {--%>
            <%--$("#isMemberRole").val(isMemberRole);--%>
        <%--}--%>
        <%--form.render();--%>


        $("button[name='btnSave']").click(function () {
            $("#roleForm").data("bootstrapValidator").resetForm();
            $("#roleForm").bootstrapValidator('validate');
            if ($("#roleForm").data('bootstrapValidator').isValid()) {
                $.ajax({
                    type: 'post',
                    url: '${allServerPath}web/sysrole/save.htmls',
                    data: $("#roleForm").serialize(),
                    dataType: 'JSON',
                    success: function (data) {
                        if (data.success) {
                            layer.msg("保存成功.");
                            // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            // parent.layer.close(index); //再执行关闭
                        } else {
                            layer.msg(data.message);
                        }
                    },
                    error: function () {
                        layer.msg("保存失败.");
                    }
                });
            }
        });

        $('#roleForm')
            .bootstrapValidator({
                live: 'disabled',//验证时机
                message: 'This value is not valid',
                submitButtons: '#btnSave',//指定提交按钮
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    name: {
                        validators: {
                            notEmpty: {
                                message: '不能为空'
                            }
                        }
                    }
                }
            });
    });
</script>
</body>
</html>
